home *** CD-ROM | disk | FTP | other *** search
- Path: castle.nando.net!news
- From: actuary@nando.net (Bill McCarthy)
- Newsgroups: comp.lang.c
- Subject: Re: Stupid array problems
- Date: 15 Jan 1996 02:00:19 GMT
- Organization: News & Observer Public Access
- Message-ID: <4dccfj$m95@castle.nando.net>
- References: <4d9b9v$14n@paperboy.ids.net> <4dbfd1$2hpc@news.gate.net> <4dc5fv$qdr@newsreader.wustl.edu>
- Reply-To: actuary@nando.net (Bill McCarthy)
- NNTP-Posting-Host: grail801.nando.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4dc5fv$qdr@newsreader.wustl.edu>, kln@howdy.wustl.edu (Krishnamoorthy Lakshminarayan) writes:
- > Hello:
- >
- > Try this:
- >
- > void delete_array_element (char **array, //The array of strings
- > int max, // total strings in array
- > int num_del) //index you want deleted
- > {
- > for (int i=max-1; i>num_del; i++) //max-1, because you've deleted
- > //one element
- > {
- > array[i] = array[i-1];
- > }
- >
- > }
-
- This won't compile. It's not C (you can't declare variables in a
- for loop).
-
- Try the following function body:
-
- if ( max > 0 && num_del < max && num_del >= 0 )
- {
- free( array[num_del] ); /* only if malloc'd */
-
- while ( ++num_del < max )
- array[num_del-1] = array[num_del];
- }
-
- Bill McCarthy
- actuary@nando.net
- Wendell, NC USA
-
-